<?php
class ManagerBlog
{
	private $_db; // Instance de PDO
	private $_host = "localhost"; //sql.free.fr";
	private $_dbname = "maissa.baker";
	private $_login = "root";//maissa.baker";
	private $_pass = "root";//tunisie93";

	public function __construct()
	{

		$this->_db = mysql_connect($this->_host,
				$this->_login,
				$this->_pass)
				or die("impossibl de se connecter :". mysql_errno());
		if(!mysql_select_db($this->_dbname, $this->_db))
			echo "erreur connect bd";
	}

	public function isExist($login, $pass) {
		$q = "SELECT * from user_blog " .
				" WHERE login = '" . strtolower(mysql_real_escape_string($login)) ."' and " .
				"password = '" . md5(mysql_real_escape_string($pass)) ."'";
		$res = mysql_query($q,$this->_db);
		$row = mysql_fetch_array($res, MYSQL_ASSOC);
		if(!$res) {
			return 0;
		}
		$user = new User();
		$user->setId($row['ID']);
		$user->setEmail($row['email']);
		$user->setLogin($row['login']);
		$user->setName($row['name']);
		$user->setPass($row['password']);
		$user->setPrenom($row['prenom']);
		$user->setSuspend($row['supend']);
		if($row['type'] == 1)
			$user->setType('ADMIN');
		if($row['type'] == 2)
			$user->setType('REDAC');
		if($row['type'] == 3)
			$user->setType('USER');
		mysql_free_result($res);
		return $user;
	}

	public function deleteUser($id){
		$req = "DELETE FROM user_blog WHERE `ID`= '" + $id + "'";
		return DB_execSQL($req, $link);
	}

	public function addUser($login, $pass, $name, $prenom, $email, $type, $suspend){
		$user = new User();
		$user->setEmail(strtolower($email));
		$user->setLogin(strtolower($login));
		$user->setName(strtolower($name));
		$user->setPass($pass);
		$user->setPrenom(strtolower($prenom));
		$user->setSuspend($suspend);
		if($type == 1)
			$user->setType('ADMIN');
		if($type == 2)
			$user->setType('REDAC');
		if($type == 3)
			$user->setType('USER');

		if($user->create())
			return $user;
		unset($user);
		return null;
	}
	public function getImagesVisible(){
		return ;
	}
}